﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RabbitMQSchedulerService
{
    public class SchedulerManager : IDisposable
    {
        private bool disposed = false; // to detect redundant calls
        GrayParrot.Scheduling.Scheduler m_scheduler = null;

        public SchedulerManager()
        {
        }

        //~SchedulerManager()
        //{
        //    Dispose(false);
        //}

        public void Initialize()
        {
            if (m_scheduler == null)
            {
                m_scheduler = new GrayParrot.Scheduling.Scheduler();
                m_scheduler.Initialize();
                m_scheduler.Start(new GrayParrot.RabbitMQ.RunOnceTriggerListener());
            }
        }

        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    // dispose managed code...
                }

                // dispose unmanaged code...
                m_scheduler.Dispose();

                //
                disposed = true;
            }
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }
}
